import os
import sqlite3
from app import create_app

def check_database():
    """检查数据库结构"""
    app = create_app()
    
    with app.app_context():
        db_path = os.path.join(app.instance_path, 'esports.db')
        if not os.path.exists(db_path):
            print("数据库文件不存在")
            return
        
        # 使用SQLite直接连接
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()
        
        try:
            # 获取matches表的结构
            cursor.execute("PRAGMA table_info(matches)")
            columns = cursor.fetchall()
            
            print("Matches表结构:")
            for col in columns:
                print(f"{col[1]} - {col[2]} - {col[3]}")
            
            # 获取一条记录查看具体数据
            cursor.execute("SELECT * FROM matches LIMIT 1")
            row = cursor.fetchone()
            
            if row:
                print("\n示例记录:")
                for i, col in enumerate(columns):
                    try:
                        print(f"{col[1]}: {row[i]}")
                    except IndexError:
                        print(f"{col[1]}: 索引超出范围")
            else:
                print("\n没有记录")
            
        except Exception as e:
            print(f"检查失败: {str(e)}")
        finally:
            conn.close()

if __name__ == "__main__":
    check_database() 